#include "SensorDataFileOutput.h"

SensorDataFileOutput::SensorDataFileOutput (char* dataFile,
		const SensorDataInput& sensor)
		: _outStream (dataFile, std::ios::binary), _sensor (sensor)
{
	if (!_outStream) {
		printf ("Cannot open the file %s", dataFile);
		throw (-1);
	}
	SensorParameter param = _sensor.getSensorParameter ();
	param.frameWidth = (unsigned int)_sensor.getIntrinsic ().fw ();
	param.frameHeight = (unsigned int)_sensor.getIntrinsic ().fh ();
	param.writeTo (_outStream);
}

SensorDataFileOutput::~SensorDataFileOutput () {}

void SensorDataFileOutput::writeFrame ()
{
	const SensorParameter& sensorParameter = _sensor.getSensorParameter ();
	if (sensorParameter.depthPixelWidth)
		_outStream.write (_sensor.getDepthImage ()->imageData,
				sensorParameter.frameSize * sensorParameter.depthPixelWidth);
	if (sensorParameter.rgbPixelWidth)
		_outStream.write (_sensor.getRGBImage ()->imageData,
				sensorParameter.frameSize * sensorParameter.rgbPixelWidth);
}